using System;
using System.Collections.Generic;
using System.Text;

namespace MCMLXVII.Core.Common.BackEnd
{
    internal static class TracerCache
    {
        private static Queue<HostTraceEventArgs> _CaptureBuffer = new Queue<HostTraceEventArgs>();
        private static int _CaptureBufferLen = Int32.Parse(Configuration.Instance.GetSystemParameter("CaptureBufferLen"));

        internal static void AddTrace(HostTraceEventArgs TraceInfo)
        {
            lock (_CaptureBuffer)
            {
                if (_CaptureBuffer.Count >= _CaptureBufferLen)
                {
                    _CaptureBuffer.Dequeue();                
                }
                _CaptureBuffer.Enqueue(TraceInfo);            
            }        
        }

        internal static HostTraceEventArgs[] GetTrace(bool ClearTrace)
        {
            lock (_CaptureBuffer)
            {

                HostTraceEventArgs[] res = new HostTraceEventArgs[_CaptureBuffer.Count];
                _CaptureBuffer.CopyTo(res, 0);
                if (ClearTrace)
                {
                    _CaptureBuffer.Clear();
                }
                return res;
            }
        }

    }
}
